###
### Article title: "Categories, Creditworthiness and Contagion: How Investors' Shortcuts Affect Sovereign Debt Markets"
###
### Journal: International Studies Quarterly
###
### Authors:  Sarah Brooks, Ohio State University
###           Layna Mosley, University of North Carolina, Chapel Hill
###           Raphael Cunha, Ohio State University
###
###
### This code replicates all the figures in the article and its supplemental data appendix.
### The figures were produced in R version 3.1.1 (2014-07-10).
###

########################################
########################################
### FIGURES 1 & 2 OF THE MAIN TEXT #####
########################################
########################################


#######################################
# Loading necessary packages and data #
#######################################

setwd(" ") #Fill in the quotation marks with the directory path where the data set (Monthly_data.dta) is located in your computer.

install.packages("foreign", "nlme", "MASS", "ggplot2", "DataCombine", "dplyr") #Installing the packages necessary to run the code below.

#Loading the data set:
library(foreign)
monthly <- read.dta("Monthly_data.dta")


######################
# PREPARING THE DATA #
######################

#########################################################
# Lagging and differencing variables for ECM estimation #
#########################################################

#Lagging variables by one period:

vars <- c("cdslong",
          "sspread",
          "cdsfitchnosignsdiff",
          "sspreadfitchnosignsdiff",
          "fitchnosigns",
          "cdsfitchdiff",
          "fitchrating",
          "sspreadfitchdiff",
          "fitchlettercdsdiff",
          "fitchletter",
          "fitchallcdsdiff",
          "fitchall",
          "fitchinvgradecdsdiff",
          "fitchinvgrade",
          "cdsregiondiff",
          "cdsmscidiff",
          "msci",
          "cdsftsediff",
          "ftsecat",
          "sspreadfitchalldiff",
          "sspreadfitchinvdiff",
          "sspreadfitchletterdiff",
          "sspreadregiondiff",
          "sspreadftsediff",
          "sspreadmscidiff",
          "energyindex",
          "months_to_election",
          "stock",
          "usmkt",
          "ig",
          "hy",
          "trsy",
          "eqprem",
          "volprem",
          "termprem",
          "bondflo",
          "fxrate",
          "debtgni",
          "inflation",
          "budgetbal",
          "gdpcapusd",
          "usprime",
          "democracy",
          "kaopen",
          "cab") #variables to be lagged

library(DataCombine)
for(i in vars){
  monthly <- slide(monthly, Var=i, GroupVar="conum", NewVar=paste("l_",i,sep=""), slideBy=-1) #data must be sorted by country and time
}


#Differencing variables:
library(dplyr)
monthly <- monthly %.%
  group_by(conum) %.%
  mutate(d_cdslong = c(NA, diff(cdslong, lag=1))) %.%
  mutate(d_sspread = c(NA, diff(sspread, lag=1))) %.%
  mutate(d_cdsfitchnosignsdiff = c(NA, diff(cdsfitchnosignsdiff, lag=1))) %.%
  mutate(d_sspreadfitchnosignsdiff = c(NA, diff(sspreadfitchnosignsdiff, lag=1))) %.%
  mutate(d_fitchnosigns = c(NA, diff(fitchnosigns, lag=1))) %.%
  mutate(d_cdsfitchdiff = c(NA, diff(cdsfitchdiff, lag=1))) %.%
  mutate(d_fitchrating = c(NA, diff(fitchrating, lag=1))) %.%
  mutate(d_sspreadfitchdiff = c(NA, diff(sspreadfitchdiff, lag=1))) %.%
  mutate(d_fitchlettercdsdiff = c(NA, diff(fitchlettercdsdiff, lag=1))) %.%
  mutate(d_fitchletter = c(NA, diff(fitchletter, lag=1))) %.%
  mutate(d_fitchallcdsdiff = c(NA, diff(fitchallcdsdiff, lag=1))) %.%
  mutate(d_fitchall = c(NA, diff(fitchall, lag=1))) %.%
  mutate(d_fitchinvgradecdsdiff = c(NA, diff(fitchinvgradecdsdiff, lag=1))) %.%
  mutate(d_fitchinvgrade = c(NA, diff(fitchinvgrade, lag=1))) %.%
  mutate(d_cdsregiondiff = c(NA, diff(cdsregiondiff, lag=1))) %.%
  mutate(d_cdsmscidiff = c(NA, diff(cdsmscidiff, lag=1))) %.%
  mutate(d_msci = c(NA, diff(msci, lag=1))) %.%
  mutate(d_cdsftsediff = c(NA, diff(cdsftsediff, lag=1))) %.%
  mutate(d_ftsecat = c(NA, diff(ftsecat, lag=1))) %.%
  mutate(d_sspreadfitchalldiff = c(NA, diff(sspreadfitchalldiff, lag=1))) %.%
  mutate(d_sspreadfitchinvdiff = c(NA, diff(sspreadfitchinvdiff, lag=1))) %.%
  mutate(d_sspreadfitchletterdiff = c(NA, diff(sspreadfitchletterdiff, lag=1))) %.%
  mutate(d_sspreadregiondiff = c(NA, diff(sspreadregiondiff, lag=1))) %.%
  mutate(d_sspreadftsediff = c(NA, diff(sspreadftsediff, lag=1))) %.%
  mutate(d_sspreadmscidiff = c(NA, diff(sspreadmscidiff, lag=1))) %.%
  mutate(d_energyindex = c(NA, diff(energyindex, lag=1))) %.%
  mutate(d_months_to_election = c(NA, diff(months_to_election, lag=1))) %.%
  mutate(d_stock = c(NA, diff(stock, lag=1))) %.%
  mutate(d_usmkt = c(NA, diff(usmkt, lag=1))) %.%
  mutate(d_ig = c(NA, diff(ig, lag=1))) %.%
  mutate(d_hy = c(NA, diff(hy, lag=1))) %.%
  mutate(d_trsy = c(NA, diff(trsy, lag=1))) %.%
  mutate(d_eqprem = c(NA, diff(eqprem, lag=1))) %.%
  mutate(d_volprem = c(NA, diff(volprem, lag=1))) %.%
  mutate(d_termprem = c(NA, diff(termprem, lag=1))) %.%
  mutate(d_bondflo = c(NA, diff(bondflo, lag=1))) %.%
  mutate(d_fxrate = c(NA, diff(fxrate, lag=1))) %.%
  mutate(d_debtgni = c(NA, diff(debtgni, lag=1))) %.%
  mutate(d_inflation = c(NA, diff(inflation, lag=1))) %.%
  mutate(d_budgetbal = c(NA, diff(budgetbal, lag=1))) %.%
  mutate(d_gdpcapusd = c(NA, diff(gdpcapusd, lag=1))) %.%
  mutate(d_usprime = c(NA, diff(usprime, lag=1))) %.%
  mutate(d_democracy = c(NA, diff(democracy, lag=1))) %.%
  mutate(d_kaopen = c(NA, diff(kaopen, lag=1))) %.%
  mutate(d_cab = c(NA, diff(cab, lag=1)))
  

############################################
# Model Estimation, Simulations, and Plots #
############################################

###############################################################################
# Figure 1. Dynamic simulations of peer-group diffusion effects on CDS prices #
# (based on results reported in Table 2)                                      #
###############################################################################

### CDS Region (Model 1) ###

library(nlme)
model <- d_cdslong ~ l_cdslong + d_cdsregiondiff + l_cdsregiondiff + l_energyindex + l_months_to_election + d_stock + l_stock + d_usmkt + l_usmkt + l_ig + l_hy + l_trsy + l_eqprem + l_volprem + l_termprem + d_bondflo + l_bondflo + d_fxrate + l_fxrate + l_debtgni + l_inflation + l_budgetbal + l_gdpcapusd + d_usprime + l_usprime + l_democracy + l_kaopen + l_cab + as.numeric(time) + factor(conum)
mod1 <- gls(model, data=monthly, correlation=corAR1(form=~time|conum), weights=varIdent(form=~1|conum), na.action=na.omit, method="ML")

#Predicted values and confidence intervals were obtained using the simulation method proposed by King et al. (2000):
library(MASS)
sim.betas <- mvrnorm(n=1000, mu=mod1$coef, Sigma=mod1$varBeta)

n <- 7 #number of iterations (i.e., number of months to be covered by the simulation)
yhat <- matrix(NA,n,3)
#Initial values for X's
l_y <- 0
d_diff <- 50
l_diff <- 0

for (i in 1:n){
  ysim <- sim.betas[,2]*l_y + sim.betas[,3]*d_diff + sim.betas[,4]*l_diff
  yhat[i,1] <- mean(ysim)
  yhat[i,2:3] <- quantile(ysim, c(.05, .95))
  l_y <- l_y + yhat[i,1]
  d_diff <- 0
  l_diff <- 50
}

#Plot:
library(ggplot2)
yhat <- as.data.frame(yhat)
regioncds <- ggplot(yhat, aes(x=0:(n-1), y=yhat[,1])) +
  ggtitle("Region\n(model 1)") + xlab("Months after shock") +
  ylab(expression(paste(Delta,"CDS (basis points)"))) +
  geom_line(size=3.5) + geom_hline(yintercept=0) +
  theme(axis.title = element_text(size = rel(2.5)), axis.text = element_text(size = rel(2)),plot.title = element_text(size = rel(3))) +
  ylim(-3, 25) + geom_ribbon(aes(ymin=yhat[,2], ymax=yhat[,3]), alpha=0.3)
tiff("1. cds region.tif", width=800, height=800, compression="none")
regioncds
dev.off()


### Risk Rating (Model 2) ###

model <- d_cdslong ~ l_cdslong + d_cdsfitchnosignsdiff + l_cdsfitchnosignsdiff + l_fitchnosigns + d_fitchnosigns + l_energyindex + l_months_to_election + d_stock + l_stock + d_usmkt + l_usmkt + l_ig + l_hy + l_trsy + l_eqprem + l_volprem + l_termprem + d_bondflo + l_bondflo + d_fxrate + l_fxrate + l_debtgni + l_inflation + l_budgetbal + l_gdpcapusd + d_usprime + l_usprime + l_democracy + l_kaopen + l_cab + as.numeric(time) + factor(conum)
mod2 <- gls(model, data=monthly, correlation=corAR1(form=~time|conum), weights=varIdent(form=~1|conum), na.action=na.omit, method="ML")

#Simulation:
set.seed(3632)
sim.betas <- mvrnorm(n=1000, mu=mod2$coef, Sigma=mod2$varBeta)
n <- 7 #number of iterations (i.e., number of months to be covered by the simulation)
yhat <- matrix(NA,n,3)
#Initial values for X's
l_y <- 0
d_diff <- 50
l_diff <- 0

for (i in 1:n){
  ysim <- sim.betas[,2]*l_y + sim.betas[,3]*d_diff + sim.betas[,4]*l_diff
  yhat[i,1] <- mean(ysim)
  yhat[i,2:3] <- quantile(ysim, c(.05, .95))
  l_y <- l_y + yhat[i,1]
  d_diff <- 0
  l_diff <- 50
}

#Plot:
yhat <- as.data.frame(yhat)
fitchcds <- ggplot(yhat, aes(x=0:(n-1), y=yhat[,1])) +
  ggtitle("Risk Rating\n(model 2)") + xlab("Months after shock") +
  ylab(expression(paste(Delta,"CDS (basis points)"))) + geom_line(size=3.5) +
  geom_hline(yintercept=0) + theme(axis.title = element_text(size = rel(2.5)), axis.text = element_text(size = rel(2)),plot.title = element_text(size = rel(3))) +
  ylim(-3, 25) + geom_ribbon(aes(ymin=yhat[,2], ymax=yhat[,3]), alpha=0.3)
tiff("2. cds fitch.tif", width=800, height=800, compression="none")
fitchcds
dev.off()


### CDS FTSE (Model 3) ###

model <- d_cdslong ~ l_cdslong + d_cdsftsediff + l_cdsftsediff + l_energyindex + l_months_to_election + d_stock + l_stock + d_usmkt + l_usmkt + l_ig + l_hy + l_trsy + l_eqprem + l_volprem + l_termprem + d_bondflo + l_bondflo + d_fxrate + l_fxrate + l_debtgni + l_inflation + l_budgetbal + l_gdpcapusd + d_usprime + l_usprime + l_democracy + l_kaopen + l_cab + as.numeric(time) + factor(conum)
mod3 <- gls(model, data=monthly, correlation=corAR1(form=~time|conum), weights=varIdent(form=~1|conum), na.action=na.omit, method="ML")

#Simulation:
sim.betas <- mvrnorm(n=1000, mu=mod3$coef, Sigma=mod3$varBeta)

n <- 7 #number of iterations (i.e., number of months to be covered by the simulation)
yhat <- matrix(NA,n,3)
#Initial values for X's
l_y <- 0
d_diff <- 50
l_diff <- 0

for (i in 1:n){
  ysim <- sim.betas[,2]*l_y + sim.betas[,3]*d_diff + sim.betas[,4]*l_diff
  yhat[i,1] <- mean(ysim)
  yhat[i,2:3] <- quantile(ysim, c(.05, .95))
  l_y <- l_y + yhat[i,1]
  d_diff <- 0
  l_diff <- 50
}

#Plot:
yhat <- as.data.frame(yhat)
ftsecds <- ggplot(yhat, aes(x=0:(n-1), y=yhat[,1])) + ggtitle("FTSE\n(model 3)") +
  xlab("Months after shock") + ylab(expression(paste(Delta,"CDS (basis points)"))) +
  geom_line(size=3.5) + geom_hline(yintercept=0)  + theme(axis.title = element_text(size = rel(2.5)), axis.text = element_text(size = rel(2)),plot.title = element_text(size = rel(3))) +
  ylim (-3, 25) + geom_ribbon(aes(ymin=yhat[,2], ymax=yhat[,3]), alpha=0.3)
tiff("3. cds ftse.tif", width=800, height=800, compression="none")
ftsecds
dev.off()


### CDS MSCI (Model 4) ###

model <- d_cdslong ~ l_cdslong + d_cdsmscidiff + l_cdsmscidiff + l_msci + d_msci + l_energyindex + l_months_to_election + d_stock + l_stock + d_usmkt + l_usmkt + l_ig + l_hy + l_trsy + l_eqprem + l_volprem + l_termprem + d_bondflo + l_bondflo + d_fxrate + l_fxrate + l_debtgni + l_inflation + l_budgetbal + l_gdpcapusd + d_usprime + l_usprime + l_democracy + l_kaopen + l_cab + as.numeric(time) + factor(conum)
mod4 <- gls(model, data=monthly, correlation=corAR1(form=~time|conum), weights=varIdent(form=~1|conum), na.action=na.omit, method="ML")

#Simulation:
sim.betas <- mvrnorm(n=1000, mu=mod4$coef, Sigma=mod4$varBeta)

n <- 7 #number of iterations (i.e., number of months to be covered by the simulation)
yhat <- matrix(NA,n,3)
#Initial values for X's
l_y <- 0
d_diff <- 50
l_diff <- 0

for (i in 1:n){
  ysim <- sim.betas[,2]*l_y + sim.betas[,3]*d_diff + sim.betas[,4]*l_diff
  yhat[i,1] <- mean(ysim)
  yhat[i,2:3] <- quantile(ysim, c(.05, .95))
  l_y <- l_y + yhat[i,1]
  d_diff <- 0
  l_diff <- 50
}

#Plot:
yhat <- as.data.frame(yhat)
mscicds <- ggplot(yhat, aes(x=0:(n-1), y=yhat[,1])) + ggtitle("MSCI\n(model 4)") +
  xlab("Months after shock") + ylab(expression(paste(Delta,"CDS (basis points)"))) +
  geom_line(size=3.5) + geom_hline(yintercept=0) + theme(axis.title = element_text(size = rel(2.5)), axis.text = element_text(size = rel(2)),plot.title = element_text(size = rel(3))) +
  ylim(-3, 25) + geom_ribbon(aes(ymin=yhat[,2], ymax=yhat[,3]), alpha=0.3)
tiff("4. cds msci.tif", width=800, height=800, compression="none")
mscicds
dev.off()



######################################################################################
# Figure 2. Dynamic simulations of peer-group diffusion effects on sovereign spreads #
# (based on results reported in Table 3)                                             #
######################################################################################

### Spreads Region (Model 5) ###

model <- d_sspread ~ l_sspread + d_sspreadregiondiff + l_sspreadregiondiff + l_energyindex + l_months_to_election + d_stock + l_stock + d_usmkt + l_usmkt + l_ig + l_hy + l_trsy + l_eqprem + l_volprem + l_termprem + d_bondflo + l_bondflo + d_fxrate + l_fxrate + l_debtgni + l_inflation + l_budgetbal + l_gdpcapusd + d_usprime + l_usprime + l_democracy + l_kaopen + l_cab + as.numeric(time) + factor(conum)
mod5 <- gls(model, data=monthly, correlation=corAR1(form=~time|conum), weights=varIdent(form=~1|conum), na.action=na.omit, method="ML")

sim.betas <- mvrnorm(n=1000, mu=mod5$coef, Sigma=mod5$varBeta)

n <- 7 #number of iterations (i.e., number of months to be covered by the simulation)
yhat <- matrix(NA,n,3)
#Initial values for X's
l_y <- 0
d_diff <- 50
l_diff <- 0

for (i in 1:n){
  ysim <- sim.betas[,2]*l_y + sim.betas[,3]*d_diff + sim.betas[,4]*l_diff
  yhat[i,1] <- mean(ysim)
  yhat[i,2:3] <- quantile(ysim, c(.05, .95))
  l_y <- l_y + yhat[i,1]
  d_diff <- 0
  l_diff <- 50
}

#Plot:
yhat <- as.data.frame(yhat)
regionspread <- ggplot(yhat, aes(x=0:(n-1), y=yhat[,1])) + ggtitle("Region\n(model 5)") +
  xlab("Months after shock") + ylab(expression(paste(Delta,"Spread (basis points)"))) + geom_line(size=3.5) + geom_hline(yintercept=0) +
  theme(axis.title = element_text(size = rel(2.5)), axis.text = element_text(size = rel(2)),plot.title = element_text(size = rel(3))) +
  ylim (-3, 25) + geom_ribbon(aes(ymin=yhat[,2], ymax=yhat[,3]), alpha=0.3)
tiff("5. spread region.tif", width=800, height=800, compression="none")
regionspread
dev.off()


### Spreads Risk Rating (Model 6) ###

model <- d_sspread ~ l_sspread + d_sspreadfitchnosignsdiff + l_sspreadfitchnosignsdiff + l_fitchnosigns + d_fitchnosigns + l_energyindex + l_months_to_election + d_stock + l_stock + d_usmkt + l_usmkt + l_ig + l_hy + l_trsy + l_eqprem + l_volprem + l_termprem + d_bondflo + l_bondflo + d_fxrate + l_fxrate + l_debtgni + l_inflation + l_budgetbal + l_gdpcapusd + d_usprime + l_usprime + l_democracy + l_kaopen + l_cab + as.numeric(time) + factor(conum)
mod6 <- gls(model, data=monthly, correlation=corAR1(form=~time|conum), weights=varIdent(form=~1|conum), na.action=na.omit, method="ML")

sim.betas <- mvrnorm(n=1000, mu=mod6$coef, Sigma=mod6$varBeta)

n <- 7 #number of iterations (i.e., number of months to be covered by the simulation)
yhat <- matrix(NA,n,3)
#Initial values for X's
l_y <- 0
d_diff <- 50
l_diff <- 0

for (i in 1:n){
  ysim <- sim.betas[,2]*l_y + sim.betas[,3]*d_diff + sim.betas[,4]*l_diff
  yhat[i,1] <- mean(ysim)
  yhat[i,2:3] <- quantile(ysim, c(.05, .95))
  l_y <- l_y + yhat[i,1]
  d_diff <- 0
  l_diff <- 50
}

#Plot:
yhat <- as.data.frame(yhat)
fitchspread <- ggplot(yhat, aes(x=0:(n-1), y=yhat[,1])) + ggtitle("Risk Rating\n(model 6)") +
  xlab("Months after shock") + ylab(expression(paste(Delta,"Spread (basis points)"))) +
  geom_line(size=3.5) + geom_hline(yintercept=0)  + theme(axis.title = element_text(size = rel(2.5)), axis.text = element_text(size = rel(2)),plot.title = element_text(size = rel(3))) +
  ylim (-3, 25) + geom_ribbon(aes(ymin=yhat[,2], ymax=yhat[,3]), alpha=0.3)
tiff("6. spread fitch.tif", width=800, height=800, compression="none")
fitchspread
dev.off()


### Spreads FTSE (Model 7) ###

model <- d_sspread ~ l_sspread + d_sspreadftsediff + l_sspreadftsediff + l_energyindex + l_months_to_election + d_stock + l_stock + d_usmkt + l_usmkt + l_ig + l_hy + l_trsy + l_eqprem + l_volprem + l_termprem + d_bondflo + l_bondflo + d_fxrate + l_fxrate + l_debtgni + l_inflation + l_budgetbal + l_gdpcapusd + d_usprime + l_usprime + l_democracy + l_kaopen + l_cab + as.numeric(time) + factor(conum)
mod7 <- gls(model, data=monthly, correlation=corAR1(form=~time|conum), weights=varIdent(form=~1|conum), na.action=na.omit, method="ML")

sim.betas <- mvrnorm(n=1000, mu=mod7$coef, Sigma=mod7$varBeta)

n <- 7 #number of iterations (i.e., number of months to be covered by the simulation)
yhat <- matrix(NA,n,3)
#Initial values for X's
l_y <- 0
d_diff <- 50
l_diff <- 0

for (i in 1:n){
  ysim <- sim.betas[,2]*l_y + sim.betas[,3]*d_diff + sim.betas[,4]*l_diff
  yhat[i,1] <- mean(ysim)
  yhat[i,2:3] <- quantile(ysim, c(.05, .95))
  l_y <- l_y + yhat[i,1]
  d_diff <- 0
  l_diff <- 50
}

#Plot:
yhat <- as.data.frame(yhat)
ftsespread <- ggplot(yhat, aes(x=0:(n-1), y=yhat[,1])) + ggtitle("FTSE\n(model 7)") + xlab("Months after shock") +
  ylab(expression(paste(Delta,"Spread (basis points)"))) + geom_line(size=3.5) + geom_hline(yintercept=0) +
  theme(axis.title = element_text(size = rel(2.5)), axis.text = element_text(size = rel(2)),plot.title = element_text(size = rel(3))) +
  ylim (-3, 25) + geom_ribbon(aes(ymin=yhat[,2], ymax=yhat[,3]), alpha=0.3)
tiff("7. spread ftse.tif", width=800, height=800, compression="none")
ftsespread
dev.off()


### Spreads MSCI (Model 8) ###

model <- d_sspread ~ l_sspread + d_sspreadmscidiff + l_sspreadmscidiff + l_msci + d_msci + l_energyindex + l_months_to_election + d_stock + l_stock + d_usmkt + l_usmkt + l_ig + l_hy + l_trsy + l_eqprem + l_volprem + l_termprem + d_bondflo + l_bondflo + d_fxrate + l_fxrate + l_debtgni + l_inflation + l_budgetbal + l_gdpcapusd + d_usprime + l_usprime + l_democracy + l_kaopen + l_cab + as.numeric(time) + factor(conum)
mod8 <- gls(model, data=monthly, correlation=corAR1(form=~time|conum), weights=varIdent(form=~1|conum), na.action=na.omit, method="ML")

sim.betas <- mvrnorm(n=1000, mu=mod8$coef, Sigma=mod8$varBeta)

n <- 7 #number of iterations (i.e., number of months to be covered by the simulation)
yhat <- matrix(NA,n,3)
#Initial values for X's
l_y <- 0
d_diff <- 50
l_diff <- 0

for (i in 1:n){
  ysim <- sim.betas[,2]*l_y + sim.betas[,3]*d_diff + sim.betas[,4]*l_diff
  yhat[i,1] <- mean(ysim)
  yhat[i,2:3] <- quantile(ysim, c(.05, .95))
  l_y <- l_y + yhat[i,1]
  d_diff <- 0
  l_diff <- 50
}

#Plot:
yhat <- as.data.frame(yhat)
mscispread <- ggplot(yhat, aes(x=0:(n-1), y=yhat[,1])) + ggtitle("MSCI\n(model 8)") + xlab("Months after shock") +
  ylab(expression(paste(Delta,"Spread (basis points)"))) + geom_line(size=3.5) + geom_hline(yintercept=0) +
  theme(axis.title = element_text(size = rel(2.5)), axis.text = element_text(size = rel(2)), plot.title = element_text(size = rel(3))) +
  ylim (-3, 25) + geom_ribbon(aes(ymin=yhat[,2], ymax=yhat[,3]), alpha=0.3)
tiff("8. spread msci.tif", width=800, height=800, compression="none")
mscispread
dev.off()



########################################################
########################################################
### FIGURES A1 & A2 OF THE DATA APPENDIX             ###
### Descriptive Plots of Borrowing Costs by Category ###
########################################################
########################################################


### Preparing data ###

# Converting category variables to factors:
monthly$fitchinvgrade <- factor(monthly$fitchinvgrade, levels=c("0","1"), labels=c("Non-investment grade","Investment grade"))

# Creating time variable as dates:
monthly$months <- seq(as.Date("2000-10-01"), length=112, by="1 month")


##############################
# Borrowing Costs Per Region #
##############################

# Using only Asia, Post-Communist, and Latin America:
regioncds <- subset(monthly, region=="Asia" | region=="Post-Communist" | region=="Latin America")

### CDS by region ###

tiff(filename="regioncds.tif", width=800, height=500, pointsize=12)
ggplot(regioncds, aes(x=months, y=cdslong, color=region, group=region)) +
  stat_summary(fun.y = "mean", geom="line", size=1.5) +
  scale_colour_grey(name="Region") +
  ylab("CDS") +
  theme_minimal(base_size=18) +
  theme(axis.title.x = element_blank()) +
  theme(legend.position="bottom")
dev.off()

### Spread by region ###

tiff(filename="regionspread.tif", width=800, height=500)
ggplot(regioncds, aes(x=months, y=sspread, color=region, group=region)) +
  stat_summary(fun.y = "mean", geom="line", size=1.5) +
  scale_colour_grey(name="Region") +
  ylab("Bond Spread") +
  theme_minimal(base_size=18) +
  theme(axis.title.x = element_blank()) +
  theme(legend.position="bottom")
dev.off()


################################################################################
# Borrowing Costs by Fitch category (Investment Grade vs Non-Investment Grade) #
################################################################################

# Exlcuding cases with no Fitch classification (otherwise NAs appear as a category in plot)
fitchplotdata <- subset(monthly, fitchinvgrade != "NA")

### Fitch Inv.Grade vs Non-Inv.Grade (CDS) ###

tiff(filename="invgradecds.tif", width=800, height=500)
ggplot(fitchplotdata, aes(x=months, y=cdslong, color=fitchinvgrade, group=fitchinvgrade)) +
  stat_summary(fun.y = "mean", geom="line", size=1.5) +
  scale_colour_grey(name="Fitch") +
  ylab("CDS") +
  theme_minimal(base_size=18) +
  theme(axis.title.x = element_blank()) +
  theme(legend.position="bottom")
dev.off()

### Fitch Inv.Grade vs Non-Inv.Grade (Bond spread) ###

tiff(filename="invgradespread.tif", width=800, height=500)
ggplot(fitchplotdata, aes(x=months, y=sspread, color=fitchinvgrade, group=fitchinvgrade)) +
  stat_summary(fun.y = "mean", geom="line", size=1.5) +
  scale_colour_grey(name="Fitch") +
  ylab("Bond Spread") +
  theme_minimal(base_size=18) +
  theme(axis.title.x = element_blank()) +
  theme(legend.position="bottom")
dev.off()



##########################################
##########################################
### FIGURES A3-A5 OF THE DATA APPENDIX ###
### Daily CDS Price Plots              ###
##########################################
##########################################

install.packages("gridExtra", "scales")

library(scales)
library(gridExtra)
library(ggplot2)

#Loading the data:
cdsdata <- read.csv("Daily_CDS_bloomberg.csv", stringsAsFactors=F)

#Preparing the data:
cdsdata[,4] <- as.Date(as.character(cdsdata$date), "%m/%d/%Y")
colnames(cdsdata)[4] <- "newdate"
cdsdata$newdate <- as.Date(cdsdata$newdate)


### Figure A3. FTSE promotion from 'Secondary Emerging' to 'Advanced Emerging', 23 Sep 2010, Effective June 2011

#Turkey
cdsturkey1 <- subset(cdsdata, country=="Turkey" & newdate > as.Date("2010-06-23") & newdate < as.Date("2010-12-23"))
cdsturkey2 <- subset(cdsdata, country=="Turkey" & newdate > as.Date("2011-03-15") & newdate < as.Date("2011-09-15"))

turkey1 <- ggplot(cdsturkey1, aes(x=cdsturkey1$newdate, y=cdsturkey1$cds)) + xlab("") + ylab("CDS spread") + scale_x_date(labels = date_format("%b %Y")) + geom_line(size=1) + geom_vline(xintercept=as.numeric(as.Date("2010-09-23")), linetype=2) + theme_bw() + theme(panel.grid = element_blank()) + ggtitle("Reclassification announced")
turkey2 <- ggplot(cdsturkey2, aes(x=cdsturkey2$newdate, y=cdsturkey2$cds)) + xlab("") + ylab("CDS spread") + scale_x_date(labels = date_format("%b %Y")) + geom_line(size=1) + theme_bw() + theme(panel.grid = element_blank()) + ggtitle("Reclassification implemented") + annotate("rect", xmin = as.Date("2011-06-01"), xmax = as.Date("2011-06-30"), ymin = -Inf, ymax = Inf, alpha = .15)

grid.arrange(turkey1, turkey2, ncol=2, main="Turkey")

#Malaysia
cdsmalaysia1 <- subset(cdsdata, country=="Malaysia" & newdate > as.Date("2010-06-23") & newdate < as.Date("2010-12-23"))
cdsmalaysia2 <- subset(cdsdata, country=="Malaysia" & newdate > as.Date("2011-03-15") & newdate < as.Date("2011-09-15"))

malaysia1 <- ggplot(cdsmalaysia1, aes(x=cdsmalaysia1$newdate, y=cdsmalaysia1$cds)) + xlab("") + ylab("CDS spread") + scale_x_date(labels = date_format("%b %Y")) + geom_line(size=1) + geom_vline(xintercept=as.numeric(as.Date("2010-09-23")), linetype=2) + theme_bw() + theme(panel.grid = element_blank()) + ggtitle("Reclassification announced")
malaysia2 <- ggplot(cdsturkey2, aes(x=cdsmalaysia2$newdate, y=cdsmalaysia2$cds)) + xlab("") + ylab("CDS spread") + scale_x_date(labels = date_format("%b %Y")) + geom_line(size=1) + theme_bw() + theme(panel.grid = element_blank()) + ggtitle("Reclassification implemented") + annotate("rect", xmin = as.Date("2011-06-01"), xmax = as.Date("2011-06-30"), ymin = -Inf, ymax = Inf, alpha = .15)

grid.arrange(malaysia1, malaysia2, ncol=2, main="Malaysia")

#Czech Republic
cdsczech1 <- subset(cdsdata, country=="Czech Republic" & newdate > as.Date("2010-06-23") & newdate < as.Date("2010-12-23"))
cdsczech2 <- subset(cdsdata, country=="Czech Republic" & newdate > as.Date("2011-03-15") & newdate < as.Date("2011-09-15"))

czech1 <- ggplot(cdsczech1, aes(x=cdsczech1$newdate, y=cdsczech1$cds)) + xlab("") + ylab("CDS spread") + scale_x_date(labels = date_format("%b %Y")) + geom_line(size=1) + geom_vline(xintercept=as.numeric(as.Date("2010-09-23")), linetype=2) + theme_bw() + theme(panel.grid = element_blank()) + ggtitle("Reclassification announced")
czech2 <- ggplot(cdsczech2, aes(x=cdsczech2$newdate, y=cdsczech2$cds)) + xlab("") + ylab("CDS spread") + scale_x_date(labels = date_format("%b %Y")) + geom_line(size=1) + theme_bw() + theme(panel.grid = element_blank()) + ggtitle("Reclassification implemented") + annotate("rect", xmin = as.Date("2011-06-01"), xmax = as.Date("2011-06-30"), ymin = -Inf, ymax = Inf, alpha = .15)

grid.arrange(czech1, czech2, ncol=2, main="Czech Republic")

### Controls (Brazil, Colombia, Chile)
#Brazil
cdsbrazil1 <- subset(cdsdata, country=="Brazil" & newdate > as.Date("2010-06-23") & newdate < as.Date("2010-12-23"))
cdsbrazil2 <- subset(cdsdata, country=="Brazil" & newdate > as.Date("2011-03-15") & newdate < as.Date("2011-09-15"))

brazil1 <- ggplot(cdsbrazil1, aes(x=cdsbrazil1$newdate, y=cdsbrazil1$cds)) + xlab("") + ylab("CDS spread") + scale_x_date(labels = date_format("%b %Y")) + geom_line(size=1) + geom_vline(xintercept=as.numeric(as.Date("2010-09-23")), linetype=2) + theme_bw() + theme(panel.grid = element_blank()) + ggtitle("Reclassification of Turkey, Malaysia, Czech Rep announced")
brazil2 <- ggplot(cdsbrazil2, aes(x=cdsbrazil2$newdate, y=cdsbrazil2$cds)) + xlab("") + ylab("CDS spread") + scale_x_date(labels = date_format("%b %Y")) + geom_line(size=1) + theme_bw() + theme(panel.grid = element_blank()) + ggtitle("Reclassification implemented") + annotate("rect", xmin = as.Date("2011-06-01"), xmax = as.Date("2011-06-30"), ymin = -Inf, ymax = Inf, alpha = .15)

grid.arrange(brazil1, brazil2, ncol=2, main="Brazil")

#Colombia
cdscolombia1 <- subset(cdsdata, country=="Colombia" & newdate > as.Date("2010-06-23") & newdate < as.Date("2010-12-23"))
cdscolombia2 <- subset(cdsdata, country=="Colombia" & newdate > as.Date("2011-03-15") & newdate < as.Date("2011-09-15"))

colombia1 <- ggplot(cdscolombia1, aes(x=cdscolombia1$newdate, y=cdscolombia1$cds)) + xlab("") + ylab("CDS spread") + scale_x_date(labels = date_format("%b %Y")) + geom_line(size=1) + geom_vline(xintercept=as.numeric(as.Date("2010-09-23")), linetype=2) + theme_bw() + theme(panel.grid = element_blank()) + ggtitle("Reclassification of Turkey, Malaysia, Czech Rep announced")
colombia2 <- ggplot(cdscolombia2, aes(x=cdscolombia2$newdate, y=cdscolombia2$cds)) + xlab("") + ylab("CDS spread") + scale_x_date(labels = date_format("%b %Y")) + geom_line(size=1) + theme_bw() + theme(panel.grid = element_blank()) + ggtitle("Reclassification implemented") + annotate("rect", xmin = as.Date("2011-06-01"), xmax = as.Date("2011-06-30"), ymin = -Inf, ymax = Inf, alpha = .15)

grid.arrange(colombia1, colombia2, ncol=2, main="Colombia")

#Chile
cdschile1 <- subset(cdsdata, country=="Chile" & newdate > as.Date("2010-06-23") & newdate < as.Date("2010-12-23"))
cdschile2 <- subset(cdsdata, country=="Chile" & newdate > as.Date("2011-03-15") & newdate < as.Date("2011-09-15"))

chile1 <- ggplot(cdschile1, aes(x=cdschile1$newdate, y=cdschile1$cds)) + xlab("") + ylab("CDS spread") + scale_x_date(labels = date_format("%b %Y")) + geom_line(size=1) + geom_vline(xintercept=as.numeric(as.Date("2010-09-23")), linetype=2) + theme_bw() + theme(panel.grid = element_blank()) + ggtitle("Reclassification of Turkey, Malaysia, Czech Rep announced")
chile2 <- ggplot(cdschile2, aes(x=cdschile2$newdate, y=cdschile2$cds)) + xlab("") + ylab("CDS spread") + scale_x_date(labels = date_format("%b %Y")) + geom_line(size=1) + theme_bw() + theme(panel.grid = element_blank()) + ggtitle("Reclassification implemented") + annotate("rect", xmin = as.Date("2011-06-01"), xmax = as.Date("2011-06-30"), ymin = -Inf, ymax = Inf, alpha = .15)

grid.arrange(chile1, chile2, ncol=2, main="Chile")


### Figure A4. FTSE promotion, 19 Sep 2007 Announced, June 2008 Implemented

#Israel - emerging to developed
cdsisrael1 <- subset(cdsdata, country=="Israel" & newdate > as.Date("2007-06-19") & newdate < as.Date("2007-12-19"))
israel1 <- ggplot(cdsisrael1, aes(x=cdsisrael1$newdate, y=cdsisrael1$cds)) + xlab("") + ylab("CDS spread") + scale_x_date(labels = date_format("%b %Y")) + geom_line(size=1) + geom_vline(xintercept=as.numeric(as.Date("2007-09-19")), linetype=2) + theme_bw() + theme(panel.grid = element_blank()) + ggtitle("Promotion announced")

cdsisrael2 <- subset(cdsdata, country=="Israel" & newdate > as.Date("2008-03-15") & newdate < as.Date("2008-09-15"))
israel2 <- ggplot(cdsisrael2, aes(x=cdsisrael2$newdate, y=cdsisrael2$cds)) + xlab("") + ylab("CDS spread") + scale_x_date(labels = date_format("%b %Y")) + geom_line(size=1) + theme_bw() + theme(panel.grid = element_blank()) + ggtitle("Promotion implemented") + annotate("rect", xmin = as.Date("2008-06-01"), xmax = as.Date("2008-06-30"), ymin=-Inf, ymax=Inf, alpha = .15)

grid.arrange(israel1, israel2, ncol=2, main="Israel")

#Hungary - secondary to advanced emerging
cdshungary1 <- subset(cdsdata, country=="Hungary" & newdate > as.Date("2007-06-19") & newdate < as.Date("2007-12-19"))
hungary1 <- ggplot(cdshungary1, aes(x=cdshungary1$newdate, y=cdshungary1$cds)) + xlab("") + ylab("CDS spread") + scale_x_date(labels = date_format("%b %Y")) + geom_line(size=1) + geom_vline(xintercept=as.numeric(as.Date("2007-09-19")), linetype=2) + theme_bw() + theme(panel.grid = element_blank()) + ggtitle("Promotion announced")

cdshungary2 <- subset(cdsdata, country=="Hungary" & newdate > as.Date("2008-03-15") & newdate < as.Date("2008-09-15"))
hungary2 <- ggplot(cdshungary2, aes(x=cdshungary2$newdate, y=cdshungary2$cds)) + xlab("") + ylab("CDS spread") + scale_x_date(labels = date_format("%b %Y")) + geom_line(size=1) + theme_bw() + theme(panel.grid = element_blank()) + ggtitle("Promotion implemented") + annotate("rect", xmin = as.Date("2008-06-01"), xmax = as.Date("2008-06-30"), ymin=-Inf, ymax=Inf, alpha = .15)

grid.arrange(hungary1, hungary2, ncol=2, main="Hungary")

#Poland - secondary to advanced emerging
cdspoland1 <- subset(cdsdata, country=="Poland" & newdate > as.Date("2007-06-19") & newdate < as.Date("2007-12-19"))
poland1 <- ggplot(cdspoland1, aes(x=cdspoland1$newdate, y=cdspoland1$cds)) + xlab("") + ylab("CDS spread") + scale_x_date(labels = date_format("%b %Y")) + geom_line(size=1) + geom_vline(xintercept=as.numeric(as.Date("2007-09-19")), linetype=2) + theme_bw() + theme(panel.grid = element_blank()) + ggtitle("Promotion announced")

cdspoland2 <- subset(cdsdata, country=="Poland" & newdate > as.Date("2008-03-15") & newdate < as.Date("2008-09-15"))
poland2 <- ggplot(cdspoland2, aes(x=cdspoland2$newdate, y=cdspoland2$cds)) + xlab("") + ylab("CDS spread") + scale_x_date(labels = date_format("%b %Y")) + geom_line(size=1) + theme_bw() + theme(panel.grid = element_blank()) + ggtitle("Promotion implemented") + annotate("rect", xmin = as.Date("2008-06-01"), xmax = as.Date("2008-06-30"), ymin=-Inf, ymax=Inf, alpha = .15)

grid.arrange(poland1, poland2, ncol=2, main="Poland")

#Controls

#Brazil
cdsbrazil1 <- subset(cdsdata, country=="Brazil" & newdate > as.Date("2007-06-19") & newdate < as.Date("2007-12-19"))
cdsbrazil2 <- subset(cdsdata, country=="Brazil" & newdate > as.Date("2008-03-15") & newdate < as.Date("2008-09-15"))

brazil1 <- ggplot(cdsbrazil1, aes(x=cdsbrazil1$newdate, y=cdsbrazil1$cds)) + xlab("") + ylab("CDS spread") + scale_x_date(labels = date_format("%b %Y")) + geom_line(size=1) + geom_vline(xintercept=as.numeric(as.Date("2007-09-19")), linetype=2) + theme_bw() + theme(panel.grid = element_blank()) + ggtitle("Reclassification of Israel, Hungary and Poland announced")
brazil2 <- ggplot(cdsbrazil2, aes(x=cdsbrazil2$newdate, y=cdsbrazil2$cds)) + xlab("") + ylab("CDS spread") + scale_x_date(labels = date_format("%b %Y")) + geom_line(size=1) + theme_bw() + theme(panel.grid = element_blank()) + ggtitle("Reclassification implemented") + annotate("rect", xmin = as.Date("2008-06-01"), xmax = as.Date("2008-06-30"), ymin = -Inf, ymax = Inf, alpha = .15)

grid.arrange(brazil1, brazil2, ncol=2, main="Brazil")

#Colombia
cdscolombia1 <- subset(cdsdata, country=="Colombia" & newdate > as.Date("2007-06-19") & newdate < as.Date("2007-12-19"))
cdscolombia2 <- subset(cdsdata, country=="Colombia" & newdate > as.Date("2008-03-15") & newdate < as.Date("2008-09-15"))

colombia1 <- ggplot(cdscolombia1, aes(x=cdscolombia1$newdate, y=cdscolombia1$cds)) + xlab("") + ylab("CDS spread") + scale_x_date(labels = date_format("%b %Y")) + geom_line(size=1) + geom_vline(xintercept=as.numeric(as.Date("2007-09-19")), linetype=2) + theme_bw() + theme(panel.grid = element_blank()) + ggtitle("Reclassification of Israel, Hungary and Poland announced")
colombia2 <- ggplot(cdscolombia2, aes(x=cdscolombia2$newdate, y=cdscolombia2$cds)) + xlab("") + ylab("CDS spread") + scale_x_date(labels = date_format("%b %Y")) + geom_line(size=1) + theme_bw() + theme(panel.grid = element_blank()) + ggtitle("Reclassification implemented") + annotate("rect", xmin = as.Date("2008-06-01"), xmax = as.Date("2008-06-30"), ymin = -Inf, ymax = Inf, alpha = .15)

grid.arrange(colombia1, colombia2, ncol=2, main="Colombia")

#Chile
cdschile1 <- subset(cdsdata, country=="Chile" & newdate > as.Date("2007-06-19") & newdate < as.Date("2007-12-19"))
cdschile2 <- subset(cdsdata, country=="Chile" & newdate > as.Date("2008-03-15") & newdate < as.Date("2008-09-15"))

chile1 <- ggplot(cdschile1, aes(x=cdschile1$newdate, y=cdschile1$cds)) + xlab("") + ylab("CDS spread") + scale_x_date(labels = date_format("%b %Y")) + geom_line(size=1) + geom_vline(xintercept=as.numeric(as.Date("2007-09-19")), linetype=2) + theme_bw() + theme(panel.grid = element_blank()) + ggtitle("Reclassification of Israel, Hungary and Poland announced")
chile2 <- ggplot(cdschile2, aes(x=cdschile2$newdate, y=cdschile2$cds)) + xlab("") + ylab("CDS spread") + scale_x_date(labels = date_format("%b %Y")) + geom_line(size=1) + theme_bw() + theme(panel.grid = element_blank()) + ggtitle("Reclassification implemented") + annotate("rect", xmin = as.Date("2008-06-01"), xmax = as.Date("2008-06-30"), ymin = -Inf, ymax = Inf, alpha = .15)

grid.arrange(chile1, chile2, ncol=2, main="Chile")


### Figure A5. FTSE Argentina Sep 16, 2009 (to be moved to Frontier September 2010) - 2009-09-16

cdsargentina1 <- subset(cdsdata, country=="Argentina" & newdate > as.Date("2009-06-16") & newdate < as.Date("2009-12-16"))
cdsargentina2 <- subset(cdsdata, country=="Argentina" & newdate > as.Date("2010-06-15") & newdate < as.Date("2010-12-15"))

argentina1 <- ggplot(cdsargentina1, aes(x=cdsargentina1$newdate, y=cdsargentina1$cds)) + xlab("") + ylab("CDS spread") + scale_x_date(labels = date_format("%b %Y")) + geom_line(size=1) + geom_vline(xintercept=as.numeric(as.Date("2009-09-16")), linetype=2) + theme_bw() + theme(panel.grid = element_blank()) + ggtitle("Demotion announced")
argentina2 <- ggplot(cdsargentina2, aes(x=cdsargentina2$newdate, y=cdsargentina2$cds)) + xlab("") + ylab("CDS spread") + scale_x_date(labels = date_format("%b %Y")) + geom_line(size=1) + theme_bw() + theme(panel.grid = element_blank()) + ggtitle("Demotion implemented") + annotate("rect", xmin = as.Date("2010-09-01"), xmax = as.Date("2010-09-30"), ymin = -Inf, ymax = Inf, alpha = .15)

grid.arrange(argentina1, argentina2, ncol=2, main="Argentina")

#Control
#Brazil
cdsbrazil1 <- subset(cdsdata, country=="Brazil" & newdate > as.Date("2009-06-16") & newdate < as.Date("2009-12-16"))
cdsbrazil2 <- subset(cdsdata, country=="Brazil" & newdate > as.Date("2010-06-15") & newdate < as.Date("2010-12-15"))

brazil1 <- ggplot(cdsbrazil1, aes(x=cdsbrazil1$newdate, y=cdsbrazil1$cds)) + xlab("") + ylab("CDS spread") + scale_x_date(labels = date_format("%b %Y")) + geom_line(size=1) + geom_vline(xintercept=as.numeric(as.Date("2009-09-16")), linetype=2) + theme_bw() + theme(panel.grid = element_blank()) + ggtitle("Demotion of Argentina announced")
brazil2 <- ggplot(cdsbrazil2, aes(x=cdsbrazil2$newdate, y=cdsbrazil2$cds)) + xlab("") + ylab("CDS spread") + scale_x_date(labels = date_format("%b %Y")) + geom_line(size=1) + theme_bw() + theme(panel.grid = element_blank()) + ggtitle("Demotion of Argentina implemented") + annotate("rect", xmin = as.Date("2010-09-01"), xmax = as.Date("2010-09-30"), ymin = -Inf, ymax = Inf, alpha = .15)

grid.arrange(brazil1, brazil2, ncol=2, main="Brazil")



############################################
############################################
### FIGURES A6 & A7 OF THE DATA APPENDIX ###
### Daily Sovereign Bond Spread Plots    ###
############################################
############################################

#Ladoing the daily sovereign bond spread data:
bonddata <- read.csv("Daily_spreads_bloomberg.csv", stringsAsFactors=F)

#Preparing the data:
bonddata[,1] <- as.Date(as.character(bonddata$date), "%m/%d/%y")


### Figure A6. FTSE promotion from 'Secondary Emerging' to 'Advanced Emerging', 23 Sep 2010, Effective June 2011

bond1 <- subset(bonddata, date > as.Date("2010-07-23") & date < as.Date("2010-11-23"))
bond2 <- subset(bonddata, date > as.Date("2011-04-15") & date < as.Date("2011-08-15"))

#Turkey
turkey1 <- ggplot(bond1, aes(x=bond1$date, y=bond1$Turkey)) + xlab("") + ylab("Bond spread") + scale_x_date(labels = date_format("%b %Y")) + geom_line(size=1) + geom_vline(xintercept=as.numeric(as.Date("2010-09-23")), linetype=2) + theme_bw() + theme(panel.grid = element_blank()) + ggtitle("Reclassification announced")
turkey2 <- ggplot(bond2, aes(x=bond2$date, y=bond2$Turkey)) + xlab("") + ylab("Bond spread") + scale_x_date(labels = date_format("%b %Y")) + geom_line(size=1) + theme_bw() + theme(panel.grid = element_blank()) + ggtitle("Reclassification implemented") + annotate("rect", xmin = as.Date("2011-06-01"), xmax = as.Date("2011-06-30"), ymin = -Inf, ymax = Inf, alpha = .15)
grid.arrange(turkey1, turkey2, ncol=2, main="Turkey")

#Malaysia
malaysia1 <- ggplot(bond1, aes(x=bond1$date, y=bond1$Malaysia)) + xlab("") + ylab("Bond spread") + scale_x_date(labels = date_format("%b %Y")) + geom_line(size=1) + geom_vline(xintercept=as.numeric(as.Date("2010-09-23")), linetype=2) + theme_bw() + theme(panel.grid = element_blank()) + ggtitle("Reclassification announced")
malaysia2 <- ggplot(bond2, aes(x=bond2$date, y=bond2$Malaysia)) + xlab("") + ylab("Bond spread") + scale_x_date(labels = date_format("%b %Y")) + geom_line(size=1) + theme_bw() + theme(panel.grid = element_blank()) + ggtitle("Reclassification implemented") + annotate("rect", xmin = as.Date("2011-06-01"), xmax = as.Date("2011-06-30"), ymin = -Inf, ymax = Inf, alpha = .15)
grid.arrange(malaysia1, malaysia2, ncol=2, main="Malaysia")

#Czech Republic
czech1 <- ggplot(bond1, aes(x=bond1$date, y=bond1$Czech.Republic)) + xlab("") + ylab("Bond spread") + scale_x_date(labels = date_format("%b %Y")) + geom_line(size=1) + geom_vline(xintercept=as.numeric(as.Date("2010-09-23")), linetype=2) + theme_bw() + theme(panel.grid = element_blank()) + ggtitle("Reclassification announced")
czech2 <- ggplot(bond2, aes(x=bond2$date, y=bond2$Czech.Republic)) + xlab("") + ylab("Bond spread") + scale_x_date(labels = date_format("%b %Y")) + geom_line(size=1) + theme_bw() + theme(panel.grid = element_blank()) + ggtitle("Reclassification implemented") + annotate("rect", xmin = as.Date("2011-06-01"), xmax = as.Date("2011-06-30"), ymin = -Inf, ymax = Inf, alpha = .15)
grid.arrange(czech1, czech2, ncol=2, main="Czech Republic")

###Controls
#Thailand
thailand1 <- ggplot(bond1, aes(x=date, y=Thailand)) + xlab("") + ylab("Bond spread") + scale_x_date(labels = date_format("%b %Y")) + geom_line(size=1) + geom_vline(xintercept=as.numeric(as.Date("2010-09-23")), linetype=2) + theme_bw() + theme(panel.grid = element_blank()) + ggtitle("Reclassification of Turkey, Malaysia, Czech Rep announced")
thailand2 <- ggplot(bond2, aes(x=date, y=Thailand)) + xlab("") + ylab("Bond spread") + scale_x_date(labels = date_format("%b %Y")) + geom_line(size=1) + theme_bw() + theme(panel.grid = element_blank()) + ggtitle("Reclassification implemented") + annotate("rect", xmin = as.Date("2011-06-01"), xmax = as.Date("2011-06-30"), ymin = -Inf, ymax = Inf, alpha = .15)
grid.arrange(thailand1, thailand2, ncol=2, main="Thailand")

#India
india1 <- ggplot(bond1, aes(x=date, y=India)) + xlab("") + ylab("Bond spread") + scale_x_date(labels = date_format("%b %Y")) + geom_line(size=1) + geom_vline(xintercept=as.numeric(as.Date("2010-09-23")), linetype=2) + theme_bw() + theme(panel.grid = element_blank()) + ggtitle("Reclassification of Turkey, Malaysia, Czech Rep announced")
india2 <- ggplot(bond2, aes(x=date, y=India)) + xlab("") + ylab("Bond spread") + scale_x_date(labels = date_format("%b %Y")) + geom_line(size=1) + theme_bw() + theme(panel.grid = element_blank()) + ggtitle("Reclassification implemented") + annotate("rect", xmin = as.Date("2011-06-01"), xmax = as.Date("2011-06-30"), ymin = -Inf, ymax = Inf, alpha = .15)
grid.arrange(india1, india2, ncol=2, main="India")

#Indonesia
indonesia1 <- ggplot(bond1, aes(x=date, y=Indonesia)) + xlab("") + ylab("Bond spread") + scale_x_date(labels = date_format("%b %Y")) + geom_line(size=1) + geom_vline(xintercept=as.numeric(as.Date("2010-09-23")), linetype=2) + theme_bw() + theme(panel.grid = element_blank()) + ggtitle("Reclassification of Turkey, Malaysia, Czech Rep announced")
indonesia2 <- ggplot(bond2, aes(x=date, y=Indonesia)) + xlab("") + ylab("Bond spread") + scale_x_date(labels = date_format("%b %Y")) + geom_line(size=1) + theme_bw() + theme(panel.grid = element_blank()) + ggtitle("Reclassification implemented") + annotate("rect", xmin = as.Date("2011-06-01"), xmax = as.Date("2011-06-30"), ymin = -Inf, ymax = Inf, alpha = .15)
grid.arrange(indonesia1, indonesia2, ncol=2, main="Indonesia")


### Figure A7. FTSE promotion, 19 Sep 2007 Announced, June 2008 Implemented

bond3 <- subset(bonddata, date > as.Date("2007-07-19") & date < as.Date("2007-11-19"))
bond4 <- subset(bonddata, date > as.Date("2008-04-15") & date < as.Date("2008-08-15"))

#Hungary - secondary to advanced emerging
hungary1 <- ggplot(bond3, aes(x=date, y=Hungary)) + xlab("") + ylab("Bond spread") + scale_x_date(labels = date_format("%b %Y")) + geom_line(size=1) + geom_vline(xintercept=as.numeric(as.Date("2007-09-19")), linetype=2) + theme_bw() + theme(panel.grid = element_blank()) + ggtitle("Promotion announced")
hungary2 <- ggplot(bond4, aes(x=date, y=Hungary)) + xlab("") + ylab("Bond spread") + scale_x_date(labels = date_format("%b %Y")) + geom_line(size=1) + theme_bw() + theme(panel.grid = element_blank()) + ggtitle("Promotion implemented") + annotate("rect", xmin = as.Date("2008-06-01"), xmax = as.Date("2008-06-30"), ymin=-Inf, ymax=Inf, alpha = .15)
grid.arrange(hungary1, hungary2, ncol=2, main="Hungary")

#Poland - secondary to advanced emerging
poland1 <- ggplot(bond3, aes(x=date, y=Poland)) + xlab("") + ylab("Bond spread") + scale_x_date(labels = date_format("%b %Y")) + geom_line(size=1) + geom_vline(xintercept=as.numeric(as.Date("2007-09-19")), linetype=2) + theme_bw() + theme(panel.grid = element_blank()) + ggtitle("Promotion announced")
poland2 <- ggplot(bond4, aes(x=date, y=Poland)) + xlab("") + ylab("Bond spread") + scale_x_date(labels = date_format("%b %Y")) + geom_line(size=1) + theme_bw() + theme(panel.grid = element_blank()) + ggtitle("Promotion implemented") + annotate("rect", xmin = as.Date("2008-06-01"), xmax = as.Date("2008-06-30"), ymin=-Inf, ymax=Inf, alpha = .15)
grid.arrange(poland1, poland2, ncol=2, main="Poland")

#Controls
#India
india1 <- ggplot(bond3, aes(x=date, y=India)) + xlab("") + ylab("Bond spread") + scale_x_date(labels = date_format("%b %Y")) + geom_line(size=1) + geom_vline(xintercept=as.numeric(as.Date("2007-09-19")), linetype=2) + theme_bw() + theme(panel.grid = element_blank()) + ggtitle("Promotion announced")
india2 <- ggplot(bond4, aes(x=date, y=India)) + xlab("") + ylab("Bond spread") + scale_x_date(labels = date_format("%b %Y")) + geom_line(size=1) + theme_bw() + theme(panel.grid = element_blank()) + ggtitle("Promotion implemented") + annotate("rect", xmin = as.Date("2008-06-01"), xmax = as.Date("2008-06-30"), ymin=-Inf, ymax=Inf, alpha = .15)
grid.arrange(india1, india2, ncol=2, main="India")

#Colombia
colombia1 <- ggplot(bond3, aes(x=date, y=Colombia)) + xlab("") + ylab("Bond spread") + scale_x_date(labels = date_format("%b %Y")) + geom_line(size=1) + geom_vline(xintercept=as.numeric(as.Date("2007-09-19")), linetype=2) + theme_bw() + theme(panel.grid = element_blank()) + ggtitle("Promotion announced")
colombia2 <- ggplot(bond4, aes(x=date, y=Colombia)) + xlab("") + ylab("Bond spread") + scale_x_date(labels = date_format("%b %Y")) + geom_line(size=1) + theme_bw() + theme(panel.grid = element_blank()) + ggtitle("Promotion implemented") + annotate("rect", xmin = as.Date("2008-06-01"), xmax = as.Date("2008-06-30"), ymin=-Inf, ymax=Inf, alpha = .15)
grid.arrange(colombia1, colombia2, ncol=2, main="Colombia")


